App Inventor for Android: Build Your Own Apps - No Experience Required! by Jason Tyler

App Inventor for Android: Build Your Own Apps - No Experience Required! by Jason Tyler

Author:Jason Tyler
Language: eng
Format: epub, pdf
Publisher: Wiley
Published: 2011-06-13T16:00:00+00:00


A method is a prepackaged set of instructions you can reuse. The actual instruction of how to draw a line on the screen of your Android device are pretty complex. This method call allows you to just give the coordinates to the method call and let it do the dirty work.

2. Snap the Canvas1.DrawLine method into the first If block.

You need two sets of X and Y values for the Canvas1.DrawLine. The first set inform the method where to draw a line from. The second set inform it where to draw the line to. The Canvas1. Dragged event created the previous and current X/Y values that we can use.

3. Open the My Definitions drawer and locate the value prevX block. Drag the prevX block and snap it into the x1 socket on the Canvas1.DrawLine method.

4. Open the My Definitions drawer and locate the value prevY block. Drag the prevY block and snap it into the y1 socket on the Canvas1.DrawLine method. You should now have the X1 and the Y1 sockets filled with the Previous X/Y coordinates.

5. Open the My Definitions drawer and drag out the value currentX and the value currentY blocks. Snap the currentX block into the x2 socket on the Canvas1.DrawLine method. Snap the currentY block into the y2 socket on the Canvas1.DrawLine method.

You should now have the x2 and y2 blocks on the Canvas1.DrawLine block populated.

Next create the If block for the case where the varDrawType contains the value 2:

1. Select the second If block and typeblock a comparison operator. With the comparison operator selected, typeblock the varDrawType global variable block. It should auto-snap into the first socket on the comparison operator. Typeblock a numeral 2 number block and snap it into the second open socket on the comparison operator.

When the second If block tests to true, it means that the dragged event needs to create a circle. A method provided by the Canvas1 component creates a circle for you at the coordinates specified.

2. Open the Canvas1 blocks drawer and locate the call Canvas1.DrawCircle method block. Drag out the Canvas1.DrawCircle and snap it into the second If block.

The Canvas1.DrawCircle method only accepts one set of X/Y coordinates. You use the current coordinates to tell the method to draw a circle every time the current coordinates change.

3. Open the My Definitions blocks drawer and locate the currentX block. Drag the currentX block and snap it into the x socket on the Canvas1.DrawCircle block.

4. Open the My Definitions drawer and locate the currentY block. Drag the currentY block and snap it into the y socket on the Canvas1.DrawCircle block.

The other parameter that the Canvas1.DrawCircle needs is the radius of the circle in pixels. The r socket requires a number that indicates how large you want the circle to be drawn. Open the Math blocks drawer and drag out a random integer block. Snap it into the r socket on the Canvas1.DrawCircle. Change the number range on the random integer block to 5 and 20, indicating a random number of pixels from 5 to 20.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.